
import { persistReducer } from 'redux-persist'
import storage from 'redux-persist/lib/storage'

import { SEARCH_ARTISTS, SELECTED_ARTIST, SELECTED_SUBSCRIPTION } from '../actions/SearchArtistsAction';

const initialState = {
    error: null,
    searchKeyword: "",
    selectedArtist: {},
    selectedSubscription: {},
}

const persistConfig = {
    key: 'artists',
    storage,
    whitelist: ['selectedArtist'], // place to select which state you want to persist
}

const searchArtistsReducer = (state = initialState, action) => {
    switch (action.type) {
        case SEARCH_ARTISTS:
            return {
                ...state,
                searchKeyword: action.data,
            }
        case SELECTED_ARTIST:
            return {
                ...state,
                selectedArtist: action.data,
            }
        case SELECTED_SUBSCRIPTION:
            return {
                ...state,
                selectedSubscription: action.data,
            }
        default:
            return { ...state };
    }
};

export default persistReducer(persistConfig, searchArtistsReducer);